package com.sky.controller.admin;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;

@RestController("AdminOrderController")
@RequestMapping("/admin/order")
@Slf4j
@Api(tags = "用户端订单")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @GetMapping("/details/{id}")
    public Result<OrderVO> orderDetail(@PathVariable Long id)
    {   OrderVO orderVO=orderService.orderDetail(id);
        return Result.success(orderVO);
    }

    @ApiOperation("查询订单")
    @GetMapping("/conditionSearch")
    public Result<PageResult> orderPage(OrdersPageQueryDTO ordersPageQueryDTO)
    {   log.info(String.valueOf(ordersPageQueryDTO));
        PageResult pageResult = orderService.orderPage(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 查询订单状态
     * @return
     */
    @ApiOperation("各个状态")
    @GetMapping("/statistics")
    public Result statics()
    {
        OrderStatisticsVO orderStatisticsVO=orderService.orderStatisticsVO();
        return Result.success(orderStatisticsVO);
    }

    /**
     * 接单
     */
    @PutMapping("/confirm")
    @ApiOperation("接单")
    public Result confirm(@RequestBody Orders orders)
    {
        orderService.confirm(orders.getId());
        return Result.success();
    }

    @PutMapping("/delivery/{id}")
    @ApiOperation("派送")
    public Result delvery(@PathVariable Long id)
    {
        orderService.delvery(id);
        return Result.success();
    }
    @PutMapping("/complete/{id}")
    @ApiOperation("派送")
    public Result complete(@PathVariable Long id)
    {
        orderService.complete(id);
        return Result.success();
    }

    @PutMapping("/cancel")
    @ApiOperation("派送")
    public Result cancel(@RequestBody Orders orders)
    {
        orderService.Admincancel(orders);
        return Result.success();
    }

    @PutMapping("/rejection")
    @ApiOperation("拒单")
    public Result reject(@RequestBody Orders orders)
    {
        orderService.Admincancel(orders);
        return Result.success();
    }

}